package com.zhkj.txg.module.mine.popup

import android.content.Context
import android.view.View
import android.widget.EditText
import android.widget.TextView
import com.zhkj.lib.utils.ToastUtil
import com.zhkj.txg.R
import razerdp.basepopup.BasePopupWindow

class InvitePopupWindow(
    context: Context,
    private val onInviteCode: (code: String) -> Unit
) : BasePopupWindow(context) {
    override fun onCreateContentView(): View = createPopupById(R.layout.popup_invite_code)

    override fun onViewCreated(contentView: View?) {
        val etInvite = contentView?.findViewById<EditText>(R.id.etInvite)
        contentView?.findViewById<TextView>(R.id.tvConfirm)?.setOnClickListener {
            val content = etInvite?.text?.toString() ?: ""
            if (content.isEmpty()) {
                ToastUtil.show("请输入邀请码")
                return@setOnClickListener
            }
            onInviteCode(etInvite?.text.toString())
        }
        contentView?.findViewById<TextView>(R.id.tvCancel)?.setOnClickListener { dismiss() }
    }

    override fun showPopupWindow() {
        super.showPopupWindow()
        findViewById<EditText>(R.id.etInvite).setText("")
    }
}